//
//  WSZLViewController.m
//  VmiSJ
//
//  Created by 汪的一声就哭了！ on 2017/1/6.
//  Copyright © 2017年 汪的一声就哭了！. All rights reserved.
//

#import "WSZLViewController.h"

@interface WSZLViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation WSZLViewController
{
    NSString *_city;
    NSString *_province;
    NSMutableArray *_listArray;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self obtainUserData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"完善资料";
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = BackColor;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"WSZLTXTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell1"];
    [self.tableView registerNib:[UINib nibWithNibName:@"WSZLWZTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell2"];
}
#pragma mark ------------- DataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        WSZLTXTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
        cell.nameLabel.text = [_listArray[indexPath.row] allKeys].firstObject;
        cell.nameLabel.font = [UIFont systemFontOfSize:self.fontSize-1];
        cell.backgroundColor = [UIColor clearColor];
        [cell.logoImageView sd_setImageWithURL:[NSURL URLWithString:[_listArray[indexPath.row] allObjects].firstObject]];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    else {
        WSZLWZTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell2"];
        cell.nameLabel.text = [_listArray[indexPath.row] allKeys].firstObject;
        cell.nameLabel.font = [UIFont systemFontOfSize:self.fontSize-1];
        cell.detailLabel.text = [_listArray[indexPath.row] allValues].firstObject;
        cell.detailLabel.font = [UIFont systemFontOfSize:self.fontSize-1];
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _listArray.count;
}
#pragma mark ------------ tableView代理
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        return 70;
    }
    return 45;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        HeadImageViewController *viewC = [[HeadImageViewController alloc] init];
        viewC.imageStr = [_listArray[0] allValues].firstObject;
        [self.navigationController pushViewController:viewC animated:YES];
    }
    if ((indexPath.row < 5 && indexPath.row > 0) || indexPath.row == 6) {
        GSMCViewController *viewC = [[GSMCViewController alloc] init];
        viewC.titleStr = [_listArray[indexPath.row] allKeys].firstObject;
        viewC.string = [_listArray[indexPath.row] allValues].firstObject;
        [viewC setHidesBottomBarWhenPushed:YES];
        viewC.modalTransitionStyle = UIModalTransitionStylePartialCurl;
        
        if (indexPath.row == 2) {
            CATransition *transition = [CATransition animation];
            transition.duration = 0.3f;
            transition.type = kCATransitionMoveIn;
            transition.subtype = kCATransitionFromTop;
            [self.navigationController.view.layer addAnimation:transition forKey:nil];
            [self.navigationController pushViewController:viewC animated:YES];
        } else if (indexPath.row == 4) {
            CATransition *transition = [CATransition animation];
            transition.duration = 0.3f;
            transition.type = kCATransitionMoveIn;
            transition.subtype = kCATransitionFromTop;
            [self.navigationController.view.layer addAnimation:transition forKey:nil];
            [self.navigationController pushViewController:viewC animated:YES];
        } else {
            [self.navigationController pushViewController:viewC animated:YES];
        }
    }
    if (indexPath.row == 5) {
        FBCSViewController *fbcsVC = [[FBCSViewController alloc] init];
        fbcsVC.provinceStr = _province;
        fbcsVC.cityStr = _city;
        [self.navigationController pushViewController:fbcsVC animated:YES];
    }
}
#pragma mark -------------- 用户信息网络请求
- (void)obtainUserData
{
    [NetRequiest handleDataWithString:[NSString stringWithFormat:@"%@",HTTPLOAD] dictionary:@{@"v1":@"userinfo",@"uid":UID} HUD:YES block:^(id responseObject) {
        if ([responseObject[@"code"] isEqual:@200]) {
            _listArray = [NSMutableArray array];
            [_listArray addObject:@{@"LOGO":responseObject[@"result"][@"img_url"]}];
            [_listArray addObject:@{@"公司名称":responseObject[@"result"][@"company_name"]}];
            [_listArray addObject:@{@"公司简称":responseObject[@"result"][@"company_abbreviated"]}];
            [_listArray addObject:@{@"联系人":responseObject[@"result"][@"charity_name"]}];
            [_listArray addObject:@{@"手机号码":responseObject[@"result"][@"charity_telephone"]}];
            [_listArray addObject:@{@"所在位置":[NSString stringWithFormat:@"%@ %@",responseObject[@"result"][@"province"],responseObject[@"result"][@"shi"]]}];
            _province = responseObject[@"result"][@"province"];
            _city = responseObject[@"result"][@"shi"];
            [_listArray addObject:@{@"详细地址":responseObject[@"result"][@"company_site"]}];
            [self.tableView reloadData];
        } else {
            [[SQShowMessage shareMessage] showMessageWithStr:responseObject[@"msg"]];
        }
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
